package com.demo.order_service.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.demo.order_service.model.entity.Order;


/** * @author 付嘉星 
/** * ٩(*Ӧ)و写的全对
/** * 困到昏厥(✽ ﾟдﾟ ✽)  
/** * @date 创建时间：2018年4月19日 上午11:09:47 
/** * @version 1.0 */

@Mapper
@Repository
public interface OrderDao {
	public static final String TABLE_NAME = " orderinfo ";
	public static final String SELECT_COLUMN = "oid,otime,commodityid,Comamount,merchantname,Merchantress," +
            "ordertotal,payment,ostatus,uname,address,phone";
    public static final String INSERT_COLUMN = " otime,commodityid,Comamount,merchantname,Merchantress," +
            "ordertotal,payment,ostatus,uname,address,phone";
    public static final String INSERT_PARAMS = " #{otime},#{commodityid},#{comamount},#{merchantname},#{merchantress}," +
            "#{ordertotal},#{payment},#{ostatus},#{uname},#{address},#{phone} ";
    public static final String UPDATE_OSTATUS = "ostatus";
    //public static final String UPDATE_ASTATUS = "#{oid},#{ostatus}";

    @Select(" SELECT * FROM orderinfo")
    List<Order> selectAll();

    @Insert(" INSERT INTO " + TABLE_NAME +
            " ( " + INSERT_COLUMN + " ) " +
            " VALUES( " + INSERT_PARAMS + " ) ")
    int insertOrder(Order order);
 
    @Select(" SELECT " + SELECT_COLUMN +
            " FROM " + TABLE_NAME +
            " WHERE oid = #{oid}")
    Order selectById(Long oid);

    @Delete(" DELETE " +
            " FROM " + TABLE_NAME +
            " WHERE oid = #{oid}")
    int deleteById(Long oid);
    
    @Update(" UPDATE " + TABLE_NAME +
    		" SET " + UPDATE_OSTATUS +" = " + " #{ostatus} " + 
    		" WHERE oid = #{oid}")
    int updateById(Order order);
}


